home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 42 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. From: "Lassi A. Tuura" <Lassi.Tuura@hut.fi>
  2. Message-ID: <l8291j9wix9.fsf@neppari.cs.hut.fi>
  3. X-Original-Date: 15 Jan 1996 17:56:34 +0200
  4. Path: in2.uu.net!bounce-back
  5. Date: 16 Jan 96 10:17:43 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: can initialization be used with new[]?
  9. Organization: Helsinki University of Technology, Finland
  10. Reply-To: Lassi.Tuura@hut.fi
  11. X-Newsreader: Gnus v5.1
  12. X-Disclaimer: This message represents at most my opnions
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMPt/DOEDnX0m9pzZAQHVAAGAkRzyMC0S6KFH/bbI6P3nVZ54dL21011D
  15.     cQWluJ2rd02zmucddFrpSO6/ntpj0UFq
  16.     =273G
  17.  
  18. One compiler I need to use has problems with the following code:
  19. ---------------
  20. #include <new.h>
  21. class T {
  22. public:
  23.     T (int n) : _n (n) { }
  24.     T (const T &ref) : _n (ref._n) { }
  25.     ~T () { }
  26.  
  27. private:
  28.     int _n;
  29. };
  30.  
  31. void f ()
  32. {
  33.      T *ptr = new T [10] (1);  // line 14
  34. }
  35. ---------------
  36.  
  37. In particular, it complains about the initializer to the vector new:
  38.   CC: "test.cc", line 14: error: initializer for array of class object
  39.               created using `new' (1248)
  40.  
  41. Another compiler has no problems with the code, and the one giving the
  42. error message has not proved to be reliable.  The question is: Is this
  43. legal C++?  I read thru 5.3.4 from the april draft and as far as I
  44. understood the code was flagged ill-formed.  Did I interpret the draft
  45. correctly?  If I did, how am I supposed to allocate an array of
  46. objects of class T?  With explicit calls to operator new and placement
  47. new?
  48.  
  49. BTW, is either comp.lang.c++.moderated or comp.std.c++ archived
  50. somewhere?  I recall I have read something about this matter some time
  51. back.
  52.  
  53. //LaT
  54. ---
  55. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  56.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  57.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  58.